package com.mitdy.sg.data.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mitdy.sg.common.bean.Pagination;
import com.mitdy.sg.data.mapper.GameMapper;
import com.mitdy.sg.data.vo.GameVO;

@Service
public class GameService {

	@Autowired
	private GameMapper gameMapper;
	
	public PageInfo<GameVO> getGamePageInfo(GameVO game, Pagination pagination) {
		Page<GameVO> page = PageHelper.startPage(pagination.getPage(), pagination.getRows());
		gameMapper.getPageInfo(game);
		PageInfo<GameVO> pageInfo = new PageInfo<GameVO>(page);
		return pageInfo;
	}
	
	public GameVO getGameById(Long gameId) {
		return gameMapper.getGameById(gameId);
	}

	@Transactional
	public GameVO addGame(GameVO game) {
		gameMapper.insert(game);
		return game;
	}

    @Transactional
	public GameVO updateGame(GameVO game) {
		gameMapper.updateByPrimaryKeySelective(game);
		return game;
	}

	@Transactional
	public void deleteGameById(Long gameId) {
		gameMapper.deleteByPrimaryKey(gameId);
	}

    public GameVO getGameByName(String name) {
        return gameMapper.getGameByName(name);
    }

}